package com.vidmt.api.modules.sys.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.service.CrudService;
import com.vidmt.api.common.cache.MyCacheManager;
import com.vidmt.api.modules.sys.dao.TraceDao;
import com.vidmt.api.modules.sys.entity.Trace;

@Service
@Transactional(readOnly = false)
@CacheConfig(cacheNames = "traceCache")
public class TraceService extends CrudService<TraceDao, Trace> {
	private static final String CACHE_NAME = "traceCache";
	private static final String PRE_UID_ = "uid_";
	@Autowired
	private MyCacheManager auxCacheManager;

	public Trace getFromCache(Long uid) {
		return (Trace) auxCacheManager.get(CACHE_NAME, PRE_UID_ + uid);
	}

	public void putToCache(Trace trace) {
		auxCacheManager.put(CACHE_NAME, PRE_UID_ + trace.getUid(), trace);
	}

	@Transactional(readOnly = true)
	public List<Trace> getByUid(Long uid) {
		return dao.getByUid(uid);
	}

	@Override
	@CacheEvict(key = "'uid_'+#trace.uid")
	public void save(Trace trace) {
		super.save(trace);
	}
}
